package chapter07;

import chapter02.MyUtil;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class demo01 {
    static int[] x;//位置
    static int n;//
    static  int[] bestx;//最大战力
    static int f;//当前战力
    static int bestf;//当前最优值
    static int[][] m;//初始位置
    public static boolean position(int k){
        for (int i = 0; i < k; i++) {
            if(x[k]==x[i]){
                return false;
            }

        }
        return true;
    }
    public static void soder(int i) {
        if (i > n) {
            int t = 0;
            for (int j = 0; j < n; j++)
                t += m[x[j]][j];
            if (t > bestf) {
                bestf = t;
                for (int j = 0; j < n; j++)
                    bestx[j] = x[j];
            }
        } else {
            for (int j = i; j < n; j++) {


                int temp = x[i];
                x[i] = x[j];
                x[j] = temp;

                soder(i + 1);

                temp = x[i];
                x[i] = x[j];
                x[j] = temp;

            }
        }
    }

    public static void main(String[] args) {
        FileInputStream fileInputStream = null;
        try {
            fileInputStream = new FileInputStream("src\\data.txt");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        Scanner scanner =new Scanner(fileInputStream);
        int n=scanner.nextInt();
        System.out.println(n);
        int[][] m;
        m = new int[n+1][n+1];
        x = new int[n+1];
        bestx = new int[n+1];
        f = 0;

        // 读入数据矩阵
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {

                m[i][j] = scanner.nextInt();
                // System.out.println(M[i][j] + " ");
            }
        }
        for (int i = 1; i <= n; i++) {
            x[i] = i;
        }
        f=0;
        bestx=new int[n+1];
        bestf = 0;
        //回溯找到最优值
        soder(0);
        System.out.println(bestf);
        for (int i = 1; i <= n; i++) {
            System.out.println( bestx[i] + " ");
        }
        System.out.println();
        MyUtil.printM(m, 1, 3);
    }

}
